<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/1
 * Time: 22:03
 */

namespace Lib\Api;


class AgentSettlementApi extends UtilsApi {
    private static $modelName = 'AgentSettlement';

    /** 获取机构结算列表
     * @param $where
     * @param $left
     * @param int $page_num
     * @param int $page_size
     * @param string $field
     * @param string $order
     * @return mixed
     */
    public static function getList($where, $left, $page_num = 1, $page_size = 15, $field = "*", $order = "*") {
        $model = M();
        $list = $model->table('fs_agent_settlement a')
            ->join($left)
            ->field($field)
            ->where($where)
            ->page($page_num, $page_size)
            ->order($order)
            ->select();
        return $list;
    }

    /** 获取机构结算总数
     * @param $where
     * @param $left
     * @return mixed
     */
    public static function getTotal($where, $left="") {
        $model = M();
        $total = $model->table('fs_agent_settlement a')
            ->join($left)
            ->where($where)
            ->count('a.id');

        return $total;
    }

    public static function getSum($where, $field,  $left="") {
        $model = M();
        $total = $model->table('fs_agent_settlement a')
            ->join($left)
            ->where($where)
            ->sum($field);
        return $total;
    }

    /** 获取机构结算信息
     * @param $where
     * @param $filed
     * @return mixed
     */
    public static function getInfo($where, $filed= "*") {
        $manager = parent::getInfo(AgentSettlementApi::$modelName, $where, $filed);
        return $manager;
    }

    /** 添加机构结算
     * @param $data
     * @return mixed
     */
    public static function add($data) {
        $id = parent::add(AgentSettlementApi::$modelName, $data);
        return $id;
    }

    /** 修改机构结算
     * @param $data
     * @return bool
     */
    public static function save($data) {
       $state = parent::save(AgentSettlementApi::$modelName, $data);
        return $state;
    }

    /** 删除机构结算
     * @param $where
     */
    public static function delete($where) {
        parent::delete(AgentSettlementApi::$modelName, $where);
    }

    /** 批量添加数据
     * @param $data
     * @return mixed
     */
    public static function addAll($data) {
        $model = M(AgentSettlementApi::$modelName);
        return $model->addAll($data);
    }
}